
package com.useractionsmodule.dao;
import com.useractionsmodule.bean.*;
import java.sql.*;
import java.util.*;
import util.*;
public class TbUserActionsDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbUserActions tbUserActions=null;
    private List<TbUserActions> tbUserActionsList=null;

    public boolean add(TbUserActions inTbUserActions){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_UserActions(UserActionName,UserActionMemo,CreateTime) values(?,?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbUserActions.getUserActionName());
        pt.setString(2,inTbUserActions.getUserActionMemo());
        pt.setString(3,inTbUserActions.getCreateTime());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public boolean del(int inUserAction){
        return UtilDAO.del("Tb_UserActions", "UserAction", inUserAction);
    }
    public boolean edit(TbUserActions inTbUserActions){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_UserActions set UserAction=?,UserActionName=?,UserActionMemo=?,CreateTime=? where UserAction=?";
        pt = conn.prepareStatement(sql);
        
        pt.setInt(1,inTbUserActions.getUserAction());
        pt.setString(2,inTbUserActions.getUserActionName());
        pt.setString(3,inTbUserActions.getUserActionMemo());
        pt.setString(4,inTbUserActions.getCreateTime());
        pt.setInt(5,inTbUserActions.getUserAction());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return flag;
    }
    public TbUserActions getTbUserActionsByUserAction(int inUserAction) {
        tbUserActions=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_UserActions where UserAction=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inUserAction);
            rs = pt.executeQuery();
            while (rs.next()) {
                if (tbUserActions == null)tbUserActions = getTbUserActions(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbUserActions;
    }
    public List<TbUserActions> getTbUserActionsAll() {
        tbUserActionsList=new ArrayList<TbUserActions>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_UserActions";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbUserActionsList.add(getTbUserActions(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbUserActionsList;
    }
    public List<TbUserActions> getTbUserActionsAll(VskPage vp) {
        tbUserActionsList=new ArrayList<TbUserActions>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_UserActions";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_UserActions", "UserAction"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbUserActionsList.add(getTbUserActions(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
    ConnectDB.closeSqlConnection();
            
        }
        return tbUserActionsList;
    }
    public TbUserActions getTbUserActions(ResultSet rs) throws Exception{
        TbUserActions tbUserActions = new TbUserActions();
        tbUserActions.setUserAction(rs.getInt("UserAction"));
        tbUserActions.setUserActionName(rs.getString("UserActionName"));
        tbUserActions.setUserActionMemo(rs.getString("UserActionMemo"));
        tbUserActions.setCreateTime(rs.getString("CreateTime"));
        return tbUserActions;
    }
}
